<?php



/**
 * Radcodes - SocialEngine Module
 *
 * @category   Application_Extensions
 * @package    Gmap
 * @copyright  Copyright (c) 2009-2010 Radcodes LLC (http://www.radcodes.com)
 * @license    http://www.radcodes.com/license/
 * @version    $Id$
 * @author     Vincent Van <vincent@radcodes.com>
 */
 
 
 
class Gmap_Widget_ListMostViewedController extends Engine_Content_Widget_Abstract
{

  public function indexAction()
  {
  	
    // Don't render this if not authorized
    $viewer = Engine_Api::_()->user()->getViewer();

    $this->view->titlelength = $this->_getParam('titlelength', 28);
    $this->view->items_per_page = $max = $this->_getParam('max', 5);
    $this->view->show_details = $this->_getParam('details', 0);
    $this->view->show_photo = $this->_getParam('photo', 1);
    $this->view->show_period = $period = $this->_getParam('period', 30);
    
    $values = array(
      'order' => 'view_count',
      'order_direction' => 'DESC',
      'limit' => $this->view->items_per_page,
    );    
    
    if ($period) {
      $values['start_date'] = time() - $period * 86400;
    }       
    
    if (!$this->view->items_per_page)
    {
      return $this->setNoRender();
    }

    $this->view->paginator = $paginator = Engine_Api::_()->gmap()->getMappableGmapsPaginator($values);
      // Do not render if nothing to show
    if( $paginator->getTotalItemCount() <= 0 ) {
      return $this->setNoRender();
    }
  }

}